// 1. 将所有的可选项 变成必选项
type MustType<T> = {
  -readonly // 映射
  [P in keyof T]-?: T[P];
};

// -?
// -readonly
type Person12 = {
  readonly username?: string;
  password?: string;
};

type A12 = MustType<Person12>;

const a0728: A12 = {
  username: "123",
  password: "123",
};

// 将所有的readonly 去掉

// 写一个类型
//
type MyPick<T, U extends keyof T> = {
  [P in U]: T[P];
};

const a07281: MyPick<{ a: number; b: string }, "a"> = {
  a: 123,
};

// 1. extends : 比较两个联合类型 一项一项比较  "a" : U ;  A:{} extends B:{} 约束
// never : 不代表任何值
type MyExclude<T, U> = T extends U ? never : T; // 从T中排除U 这两个类型都是 联合类型
type ExcludeExample = MyExclude<"a" | "b" | "c" | "z" | "d", "a" | "b" | "d">;

const excludeExample: ExcludeExample = "c"; // "z" | "c"

//
type MyExtract<T, U> = T extends U ? T : never; //

type ExtractExample = MyExtract<"a" | "b" | "c" | "z" | "d", "a" | "b" | "d">;

const extractExample: ExtractExample = "a"; // "a" | "b" | "b"


type MyNonNullable<T> = T extends null | undefined ? never  : T// 去掉null和undefined类型
type MyNonNullableExample = MyNonNullable<string|number|undefined|null>;
const myNonNullable: MyNonNullableExample = 123//string|number 

// 